package games.gong.durid.service.impl;

import games.gong.durid.entity.UserRole;
import games.gong.durid.mapper.UserRoleMapper;
import games.gong.durid.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class UserRoleServiceImpl implements UserRoleService {
    
    @Autowired
    private UserRoleMapper userRoleMapper;
    
    @Override
    public int addUserRole(UserRole userRole) {
        userRole.setCreateTime(LocalDateTime.now());
        return userRoleMapper.insert(userRole);
    }
    
    @Override
    public int deleteUserRole(Long id) {
        return userRoleMapper.deleteById(id);
    }
    
    @Override
    public int deleteUserRoleByUserIdAndRoleId(Long userId, Long roleId) {
        return userRoleMapper.deleteByUserIdAndRoleId(userId, roleId);
    }
    
    @Override
    public UserRole getUserRoleById(Long id) {
        return userRoleMapper.selectById(id);
    }
    
    @Override
    public List<UserRole> getUserRolesByUserId(Long userId) {
        return userRoleMapper.selectByUserId(userId);
    }
    
    @Override
    public List<UserRole> getUserRolesByRoleId(Long roleId) {
        return userRoleMapper.selectByRoleId(roleId);
    }
}